package selectionsort

import (
	//"log"
)

//SelectionSort 选择排序 不稳定算法
//最坏：O(n^2) 最好：O(n^2) 平均：O(n^2)
//不稳定的原因是无序交换元素
func SelectionSort(nums []int) []int {
	ln := len(nums)
	for i := 0; i < ln-1; i++ {
		tmp := nums[i]
		pos := i
		for j := i+1; j < ln; j++ {
			if tmp > nums[j] {
				tmp = nums[j]
				pos = j
			}
		}
		nums[pos], nums[i] = nums[i], tmp
	}
	return nums
}